package com.springboot.controller;

import com.springboot.common.ReturnObject;
import com.springboot.model.User;
import com.springboot.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


/**
 * @Description TODO
 * @Date 2022/2/21 17:07
 * @Version 1.0
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 跳转登陆页面
     * @return
     */
    @RequestMapping("/toLogin.do")
    public String toLogin(){
        return "static/web/login";
    }

    /**
     * 登录控制
     * @param loginUser 用户输入用户名
     * @param loginPwd 用户输入密码
     * @return
     */
    @RequestMapping("/login.do")
    @ResponseBody
    public ReturnObject login (String loginUser, String loginPwd){

        //查询数据库数据
        User user = userService.selectUserByNameAndPwd(loginUser, loginPwd);

        if (user!=null){
            System.out.println("用户登录成功");
            return new ReturnObject(1,"登录成功",null);
        }
        return new ReturnObject(0,"用户名或密码错误",null);
    }

}
